package com.nintendo.controller;

import com.nintendo.exceptions.GraceException;
import com.nintendo.pojo.FriendInfoVo;
import com.nintendo.pojo.Friendship;
import com.nintendo.pojo.Users;
import com.nintendo.pojo.bo.NewFriendRequestBO;
import com.nintendo.pojo.vo.NewFriendsVO;
import com.nintendo.result.GraceJSONResult;
import com.nintendo.service.FriendShipService;
import com.nintendo.service.UsersTSTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/friendShips")
public class FriendShipController {
    @Autowired
    private FriendShipService friendShipService;
    @Autowired
    private UsersTSTService usersTSTService;
    @PostMapping("/sendRequest")
    public GraceJSONResult sendRequest(@RequestBody NewFriendRequestBO newFriendRequestBO,
                                       HttpServletRequest request){
        friendShipService.sendRequest(newFriendRequestBO,request);
        return GraceJSONResult.ok();
    }
    /**
     * 查询好友请求列表
     */
    @PostMapping("/findRequest")
    public GraceJSONResult findMyRequest(HttpServletRequest request){
        List<NewFriendsVO> users = usersTSTService.findMyRequest(request);
        return GraceJSONResult.ok(users);
    }
    /**
     * 拒绝好友请求
     */
    @PostMapping("/rejected")
    public GraceJSONResult rejected(@RequestParam("friendRequestId")String friendRequestId){
        friendShipService.rejected(friendRequestId);
        return GraceJSONResult.ok();
    }
    /**
     * 同意好友申请
     */
    @PostMapping("/accept")
    public GraceJSONResult accept(@RequestParam("friendRequestId")String friendRequestId){
        friendShipService.accept(friendRequestId);
        return GraceJSONResult.ok();
    }
    /**
     * 查询我的好友列表
     */
    @PostMapping("/searchMyFriend")
    public GraceJSONResult searchMyFriend(HttpServletRequest request){
        List<Users> users = usersTSTService.searchMyFriend(request);
        return GraceJSONResult.ok(users);
    }
    /**
     * 拉黑好友
     */
    @PostMapping("/toBeBlack")
    public GraceJSONResult toBeBlack(HttpServletRequest request,
                                     @RequestParam("friendId")String friendId){
        System.out.println("friendId:"+friendId);
        friendShipService.toBeBlack(request,friendId);
        return GraceJSONResult.ok();
    }
    /**
     * 取消拉黑好友
     */
    @PostMapping("/noBeBlack")
    public GraceJSONResult noBlack(HttpServletRequest request,
                                     @RequestParam("friendId")String friendId){
        friendShipService.noBlack(request,friendId);
        return GraceJSONResult.ok();
    }
    /**
     * 查询好友备注信息
     */
    @PostMapping("/searchMyFriendUserInfo")
    public GraceJSONResult searchMyFriendUserInfo(HttpServletRequest request,@RequestParam("friendId")String friendId){
        FriendInfoVo friendInfoVo = friendShipService.searchMyFriendUserInfo(request,friendId);
        return GraceJSONResult.ok(friendInfoVo);
    }
    /**
     * 根据friendShipId查询好友关系信息
     */
    @PostMapping("/searchMyFriendUserInfoById")
    public GraceJSONResult searchMyFriendUseInfoById(@RequestParam("friendShipId")String friendShipId){
        Friendship friendship = friendShipService.searchMyFriendUserInfoById(friendShipId);
        return GraceJSONResult.ok(friendship);
    }
    /**
     * 更改好友备注
     */
    @PostMapping("/updateFriendUserInfoById")
    public GraceJSONResult updateFriendUserInfoById(@RequestParam("friendShipId")String friendShipId,
                                                    @RequestParam("remark")String remark){
        friendShipService.updateFriendUserInfoById(friendShipId,remark);
        return GraceJSONResult.ok();
    }
}
